home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / app / gximage.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-16  |  2.7 KB  |  137 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include <gtk/gtk.h>
  22.  
  23. #include "apptypes.h"
  24.  
  25. #include "appenv.h"
  26. #include "colormaps.h"
  27. #include "gimage.h"
  28. #include "gximage.h"
  29.  
  30. typedef struct _GXImage  GXImage;
  31.  
  32. struct _GXImage
  33. {
  34.   long width, height;        /*  width and height of ximage structure    */
  35.  
  36.   GdkVisual *visual;        /*  visual appropriate to our depth         */
  37.   GdkGC *gc;            /*  graphics context                        */
  38.  
  39.   guchar *data;
  40. };
  41.  
  42.  
  43. /*  The static gximages for drawing to windows  */
  44. static GXImage *gximage = NULL;
  45.  
  46. #define QUANTUM   32
  47.  
  48. /*  STATIC functions  */
  49.  
  50. static GXImage *
  51. create_gximage (GdkVisual *visual, int width, int height)
  52. {
  53.   GXImage * gximage;
  54.  
  55.   gximage = g_new (GXImage, 1);
  56.  
  57.   gximage->visual = visual;
  58.   gximage->gc = NULL;
  59.  
  60.   gximage->data = g_malloc (width * height * 3);
  61.  
  62.   return gximage;
  63. }
  64.  
  65. static void
  66. delete_gximage (GXImage *gximage)
  67. {
  68.   g_free (gximage->data);
  69.   if (gximage->gc)
  70.     gdk_gc_destroy (gximage->gc);
  71.   g_free (gximage);
  72. }
  73.  
  74. /****************************************************************/
  75.  
  76.  
  77. /*  Function definitions  */
  78.  
  79. void
  80. gximage_init (void)
  81. {
  82.   gximage = create_gximage (g_visual, GXIMAGE_WIDTH, GXIMAGE_HEIGHT);
  83. }
  84.  
  85. void
  86. gximage_free (void)
  87. {
  88.   delete_gximage (gximage);
  89. }
  90.  
  91. guchar*
  92. gximage_get_data (void)
  93. {
  94.   return gximage->data;
  95. }
  96.  
  97. int
  98. gximage_get_bpp (void)
  99. {
  100.   return 3;
  101. }
  102.  
  103. int
  104. gximage_get_bpl (void)
  105. {
  106.   return 3 * GXIMAGE_WIDTH;
  107. }
  108.  
  109. int
  110. gximage_get_byte_order (void)
  111. {
  112.   return GDK_MSB_FIRST;
  113. }
  114.  
  115. void
  116. gximage_put (GdkWindow *win, int x, int y, int w, int h, int xdith, int ydith)
  117. {
  118.   /*  create the GC if it doesn't yet exist  */
  119.   if (!gximage->gc)
  120.     {
  121.       gximage->gc = gdk_gc_new (win);
  122.       gdk_gc_set_exposures (gximage->gc, TRUE);
  123.     }
  124.  
  125.   gdk_draw_rgb_image_dithalign (win,
  126.                 gximage->gc,
  127.                 x,
  128.                 y,
  129.                 w,
  130.                 h,
  131.                 /* todo: make configurable */
  132.                 GDK_RGB_DITHER_MAX,
  133.                 gximage->data,
  134.                 GXIMAGE_WIDTH * 3,
  135.                 xdith, ydith);
  136. }
  137.